﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using V5_Model;
using System.IO;
using System.Web;

namespace V5_BLL {
    public class BLLTemplate {
        DirectoryInfo[] directories;
        string _filePath;

        public BLLTemplate() {
        }

        public BLLTemplate(string filePath) {
            _filePath = filePath;
            directories = new DirectoryInfo(filePath).GetDirectories();
        }

        /// <summary>
        /// 获取所有模板信息
        /// </summary>
        /// <returns></returns>
        public List<ModelTemplate> GetAllTemplateInfo() {
            List<ModelTemplate> listtempInfo = new List<ModelTemplate>();
            string str10 = string.Empty;
            for (int i = 0; i < directories.Length; i++) {
                try {
                    ModelTemplate tpl = new ModelTemplate();
                    str10 = directories[i].Name.ToLower();
                    tpl.TemplateDir = str10;//模板目录名字
                    string filename = _filePath + "/" + str10 + "/template.config";
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(filename);//添加异常
                    XmlNode DocdNodeName = xmldoc.DocumentElement.ChildNodes[0];
                    if (DocdNodeName != null) {
                        tpl.Name = DocdNodeName.Attributes["name"].Value;
                        tpl.Image = DocdNodeName.Attributes["image"].Value;
                        tpl.Description = DocdNodeName.Attributes["description"].Value;
                        tpl.Version = DocdNodeName.Attributes["version"].Value;
                        tpl.Author = DocdNodeName.Attributes["author"].Value;
                    }
                    listtempInfo.Add(tpl);
                }
                catch (Exception) {
                    continue;
                }
            }
            return listtempInfo;
        }
    }
}
